import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    redirect: '/login',
    hidden: true
  },
  {
    path: '/Main',
    component: Layout,
    hidden: true,
    children: [{
      // hidden: false,
      path: '',
      component: () => import('@/views/Main/index'),
      meta: { title: '首页', icon: 'el-icon-data-board' }
    }]
  },
  {
    path: '/test',
    hidden: false,
    component: Layout,
    meta: { title: '信息管理', icon: 'el-icon-s-management' },
    children:[
      {
        path: 'a',
        component: () => import ('@/views/Test/index'),
        meta: { title: '测试1', icon: 'el-icon-s-flag' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
